<?php include "../public/header.php";?>
<?php include "../public/header_edit.php";?>
<link rel="stylesheet" type="text/css" href="/static/component/laytp/module/cityPicker/city-picker.css">
<body id="optPage">
<form class="layui-form layui-form-pane" id="commentForm">
    <div class="page-title"><div class="page-title-con"><span id="flowsetname"></span><div class="move_title"></div><?php include "../public/sub.php";?></div></div>
    <div class="main-container">
        <div class="block-generic">
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="edittits"><span>项目信息</span></div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label"><text>*</text>项目名称</label>
                        <div class="layui-input-block">
                            <input type="text" readonly name="enginid" class="layui-input enginid" onclick="openPage('../public/choose_engin.php?dom=enginid&page=contract_shi','80%','80%')">
                            <div class="choose_div" id="enginid" key="1"></div>
                            <span class="choose_one" onclick="openPage('../public/choose_engin.php?dom=enginid&page=contract_shi','80%','80%')"><i class="layui-icon layui-icon-search"></i></span>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="edittits"><span>收入合同信息</span></div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>合同名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="name" id="name" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">合同编号</label>
                        <div class="layui-input-block">
                            <input type="text" id="number" readonly placeholder="请输入" clearable autocomplete="off" class="layui-input disabled">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>合同类型</label>
                        <div class="layui-input-block">
                            <div id="shihetype"></div>
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>合同年份</label>
                        <div class="layui-input-block">
                            <select id="year" name="year" lay-filter="year" ></select>
                            <p class="error" id="year_error" style="margin: 0;"></p>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>发包方(甲方)</label>
                        <div class="layui-input-block">
                            <input type="text" readonly name="faer" class="layui-input faer" onclick="openPage('../public/choose_dealcom.php?dom=faer&page=contract_shi','80%','80%')">
                            <div class="choose_div" id="faer" key="1"></div>
                            <span class="choose_one" onclick="openPage('../public/choose_dealcom.php?dom=faer&page=contract_shi','80%','80%')"><i class="layui-icon layui-icon-search"></i></span>
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>承包方(乙方)</label>
                        <div class="layui-input-block">
                            <div class="tanxian">
                                <div class="tanxianclick" onclick="openPage('../public/choose_userpart.php?dom=chenger&type=dept&dept=chan&single=1','770px','490px');"></div>
                                <div class="tanxiannei" id="chenger"></div>
                            </div>
                            <div class="tancheckdiv"><div class="tancheck" onclick="openPage('../public/choose_userpart.php?dom=chenger&type=dept&dept=chan&single=1','770px','490px');"><i class="layui-icon layui-icon-search"></i></div></div>
                            <div id="chenger_tanerror" class="tanerrormsg"></div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>合同金额含税(元)</label>
                        <div class="layui-input-block">
                            <input type="text" name="money" id="money" placeholder="请输入" clearable autocomplete="off" class="layui-input moneyinput">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">税率(%)</label>
                        <div class="layui-input-block">
                            <input type="number" name="rate" id="rate" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">合同金额不含税(元)</label>
                        <div class="layui-input-block">
                            <input type="text" name="noshuifee" id="noshuifee" placeholder="自动计算：含税金额÷（1+税率/100）" readonly autocomplete="off" class="layui-input moneyinput disabled">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">合同工期(天)</label>
                        <div class="layui-input-block">
                            <input type="text" name="duration" id="duration" placeholder="请输入" clearable  autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">合同开工日期</label>
                        <div class="layui-input-block">
                            <input type="text" name="startdt" id="startdt" placeholder="请选择" clearable  autocomplete="off" class="layui-input bdate_ymd">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>!</text>合同竣工日期</label>
                        <div class="layui-input-block">
                            <input type="text" name="enddt" id="enddt" placeholder="请选择" clearable  autocomplete="off" class="layui-input bdate_ymd">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">质保金比例(%)</label>
                        <div class="layui-input-block">
                            <input type="number" name="zhirate" id="zhirate" placeholder="请输入" clearable  autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">质保金金额(元)</label>
                        <div class="layui-input-block">
                            <input type="text" name="zhifee" id="zhifee" placeholder="自动计算(合同金额*质保金比例)" disabled autocomplete="off" class="layui-input disabled moneyinput">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">质保期</label>
                        <div class="layui-input-block">
                            <input type="text" name="zhinum" id="zhinum" placeholder="请输入" clearable  autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>!</text>质保金到期日期</label>
                        <div class="layui-input-block">
                            <input type="text" name="zhidt" id="zhidt" placeholder="请选择" clearable  autocomplete="off" class="layui-input bdate_ymd">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>合同状态</label>
                        <div class="layui-input-block">
                            <select id="state" name="state" lay-filter="state" ></select>
                            <p class="error" id="state_error" style="margin: 0;"></p>
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">签订日期</label>
                        <div class="layui-input-block">
                            <input type="text" name="qiandt" id="qiandt" placeholder="请选择" clearable  autocomplete="off" class="layui-input bdate_ymd">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">合同份数</label>
                        <div class="layui-input-block">
                            <input type="text" name="henum" id="henum" placeholder="请输入" clearable  autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">是否公司业绩</label>
                        <div class="layui-input-block">
                            <select id="isyeji" name="isyeji" lay-filter="isyeji">
                                <option value="是">是</option>
                                <option value="否">否</option>
                            </select>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item height_auto">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label label_textarea">主要条款</label>
                        <div class="layui-input-block">
                            <textarea id="clause" name="clause" placeholder="请输入" class="layui-textarea"></textarea>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item height_auto">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label label_textarea">备注</label>
                        <div class="layui-input-block">
                            <textarea id="explain" name="explain" placeholder="请输入" class="layui-textarea"></textarea>
                        </div>
                    </div>
                </div>
            </div>
            <?php include '../public/upinfo.php'?>
        </div>
    </div>
</form>
<script>
    var param_id = getQueryVariable('id') || 0;

    $("#commentForm").validate({
        rules: {
            name: {required: true},
            money: {required: true},
            rate: {required: true},
        },
        messages:{
            name: {required: "请输入"},
            money: {required: "请输入"},
            rate: {required: "请输入"},
        }
    });

    layui.use(['laytp', 'form'], function() {
        var form = layui.form, layer = layui.layer;
        render_input_attr();
        facade.ajax({type: 'get', url: ask_contract_shi_edit, data:{id:param_id}}).done(function(res){
            if (res.code === 2000) {
                var data = res.data.data;

                var engininfo = res.data.engininfo;
                if(engininfo){
                    set_choose_btn('enginid',engininfo.id,engininfo.name);
                }


                $("#number").val(data.number);
                $("#name").val(data.name);
                $("#money").val(data.money);
                $("#rate").val(data.rate);
                $("#noshuifee").val(data.noshuifee);
                $("#startdt").val(data.startdt);
                $("#enddt").val(data.enddt);
                $("#duration").val(data.duration);
                $("#qiandt").val(data.qiandt);
                $("#henum").val(data.henum);
                $("#isyeji").val(data.isyeji);
                $("#zhirate").val(data.zhirate);
                $("#zhifee").val(data.zhifee);
                $("#zhinum").val(data.zhinum);
                $("#zhidt").val(data.zhidt);
                $("#clause").val(data.clause);
                $("#explain").val(data.explain);


                if(data.chenger_info.length > 0){
                    tan_tags_init('#chenger', data.chenger_info);
                }

                set_choose_btn('faer',data.faer,data.faer);

                xmselect_dan('shihetype', res.data.shihetype, data.shihetype, function (res) {
                    if(res.arr && res.arr.length > 0){
                        $("#shihetype").find('xm-select').removeClass('error');
                    }else{
                        $("#shihetype").find('xm-select').addClass('error');
                    }
                });

                xiala_zhan_one_you('year',res.data.year, data.year)
                xiala_zhan_one_you('state',res.data.state, data.state)


                initParseMoney();
                public_upload_file_load('upload_files', res.data.files);
                render_from();
            }
        });


        form.on('select(year)', function(data){
            if(data.value == ''){
                $('#year_error').show().text('请选择');
                $('#year_error').parent().find('input').addClass('select_error');
            }else{
                $('#year_error').hide();
                $('#year_error').parent().find('input').removeClass('select_error');
            }
        });
        form.on('select(state)', function(data){
            if(data.value == ''){
                $('#state_error').show().text('请选择');
                $('#state_error').parent().find('input').addClass('select_error');
            }else{
                $('#state_error').hide();
                $('#state_error').parent().find('input').removeClass('select_error');
            }
        });


        form.on('submit(add)', function(data){
            parseMoney(data);
            data.field.faer = get_choose_val('faer');
            data.field.chenger = tan_tags_getvalue("#chenger", 'dept');
            data.field.enginid = get_choose_val('enginid');

            var validRes = $("#commentForm").valid();

            formValid('enginid');
            if(data.field.enginid == undefined || !data.field.enginid){
                validRes = false;
            }

            if(!data.field.shihetype){
                $("#shihetype").find('xm-select').addClass('error');
                validRes = false;
            }else{
                $("#shihetype").find('xm-select').removeClass('error');
            }


            if(data.field.year == ''){
                $('#year_error').show().text('请选择');
                $('#year_error').parent().find('input').addClass('select_error');
                validRes = false;
            }else{
                $('#year_error').hide();
                $('#year_error').parent().find('input').removeClass('select_error');
            }

            formValid('faer');
            if(data.field.faer == undefined || !data.field.faer){
                validRes = false;
            }

            if(!data.field.chenger){
                $("#chenger").parents('.tanxian').addClass('tanerror');
                $('#chenger_tanerror').text('请选择');
                validRes = false;
            }else{
                $("#chenger").parents('.tanxian').removeClass('tanerror');
                $('#chenger_tanerror').text('');
            }

            if(data.field.state == ''){
                $('#state_error').show().text('请选择');
                $('#state_error').parent().find('input').addClass('select_error');
                validRes = false;
            }else{
                $('#state_error').hide();
                $('#state_error').parent().find('input').removeClass('select_error');
            }

            if(!validRes){return false;}





            data.field.id = param_id;
            data.field.files = public_upload_file_value('upload_files');
            data = parseMoney(data);

            facade.ajax({url: ask_contract_shi_edit, data:data.field}).done(function(res){
                if (res.code === 2000) {
                    dataPostTimeOut();
                }
            });

            return false;
        });

    });


    $("#money, #rate, #zhirate").on('input propertychange',function () {
        jisuan_money();
    });

    function jisuan_money() {
        var money = parseValidNum($("#money").val());
        var rate = parseValidNum($("#rate").val());
        var zhirate = parseValidNum($("#zhirate").val());

        var noshuifee = money/(1+rate/100);
        $("#noshuifee").val(parseFormatNum(noshuifee,2));

        var zhifee = money * zhirate / 100;
        $("#zhifee").val(parseFormatNum(zhifee,2));
    }

</script>
</body>
</html>
